package cm.iccsoft.android.telecomcost.ui;

import cm.iccsoft.android.telecomcost.DatabaseManager;
import cm.iccsoft.android.telecomcost.R;
import cm.iccsoft.android.telecomcost.TelecomCost;
import cm.iccsoft.android.telecomcost.activities.VoiceRateListActivity;
import cm.iccsoft.android.telecomcost.entities.VoiceRate;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class VoiceRateDialog extends Dialog {
	
	private DatabaseManager db;
	private Button btnCreateVoiceRate;
	private Button btnCloseVoiceRateDialog;
	private TimePickerView timePicker;;	
	private boolean shouldRefreshVoiceRateList = false;
	private VoiceRate voice_rate;

	/**
	 * @param context
	 * @param cancelable
	 * @param cancelListener
	 */
	public VoiceRateDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);		
	}

	/**
	 * @param context
	 * @param theme
	 */
	public VoiceRateDialog(Context context, int theme) {
		super(context, theme);		
	}	

	public VoiceRateDialog(Context context,
			VoiceRate voiceRate) {
		super(context);
		voice_rate = voiceRate;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i("EditVoiceRateDialog", "Creating the dialog...");
		super.onCreate(savedInstanceState);

		db = TelecomCost.getDatabaseManager();
		setContentView(R.layout.voice_rate_dialog);		
		setTitle("Edit a VoiceRate");

		timePicker = (TimePickerView) findViewById(R.id.tableRow1);
		btnCreateVoiceRate = (Button) findViewById(R.id.btnSave);
		btnCloseVoiceRateDialog = (Button) findViewById(R.id.btnClose);

		btnCreateVoiceRate.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				saveVoiceRate();
			}						
		});

		btnCloseVoiceRateDialog.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {	
				closeDialog();
			}
		});
		
		Log.i("EditVoiceRateDialog","Dialog ohne bundle created....");
	}	
	
	protected void closeDialog() {
		Log.i("EditVoiceRateDialog","closing the dialog");
		hide();
		if(shouldRefreshVoiceRateList)
		{
			VoiceRateListActivity activity = (VoiceRateListActivity)getOwnerActivity();
			activity.bindVoiceRates();
		}
		
		shouldRefreshVoiceRateList = false;
	}

	private void saveVoiceRate() {
	}

	@Override
	public void show() {
		Log.i("EditVoiceRateDialog", "showing the dialog...");
		onCreate(null);
		super.show();
		Log.i("EditVoiceRateDialog", "dialog on screen...");
	}
	
	@Override
	protected void onStart() {
		Log.i("EditVoiceRateDialog", "Starting the dialog...");
		super.onStart();
		Log.i("EditVoiceRateDialog", "dialog started...");
	}

	@Override
	protected void onStop() {
		Log.i("EditVoiceRateDialog", "Stopping the dialog...");
		super.onStop();
		Log.i("EditVoiceRateDialog", "dialog stopped...");
	}

}
